<!-- 左侧导航栏，独立模块 -->

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const $router = useRouter()


const onActive = (e) => {
    // 获取当前元素的父元素
    const parent = e.target.parentElement
    if (parent.classList.contains('active')) {
        // 如果当前元素已经处于激活状态，则不做任何操作
        return
    } else {
        // 如果当前元素没有处于激活状态，则移除所有兄弟元素的激活状态，并给当前元素添加激活状态
        const siblings = parent.parentElement.children
        for (let i = 0; i < siblings.length; i++) {
            siblings[i].classList.remove('active')
        }
        parent.classList.add('active')
    }
}




onMounted(() => {

})

</script>

<template>
    <div class="leftNav">
        <div class="logo">
            <img src="../assets/logo.png" alt="">
        </div>
        <div class="user-head">未登录</div>
        <div class="nav-icon">
            <div class="active icon-item" @click="onActive($event)">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-home2"></use>
                </svg>
                <li @click=" $router.push('/home')">首页</li>
            </div>
            <div class="icon-item" @click="onActive($event)">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-zhiwu"></use>
                </svg>
                <li @click=" $router.push('/article')">博文</li>
            </div>
            <div class="icon-item" @click="onActive($event)">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-shumu"></use>
                </svg>
                <li @click=" $router.push('/about')">关于</li>
            </div>
            <div class="icon-item" @click="onActive($event)">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-beijingyinle"></use>
                </svg>
                <li @click=" $router.push('/music')">音乐</li>
            </div>
            <div class="icon-item" @click="onActive($event)">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-yonghu"></use>
                </svg>
                <li @click="$router.push('/user')">用户</li>
            </div>
        </div>

    </div>
</template>

<style lang="scss" scoped>
// 动画
// 选项的动画
@keyframes hoverLi {
    0% {
        transform: translateY(-40px);
    }

    100% {
        transform: translateY(0);
    }
}

@keyframes hoverLiafter {
    0% {
        transform: translateX(-50%) translateY(60px);

    }

    100% {
        transform: translateX(-50%) translateY(0);
    }
}

// 动画结束

.leftNav {
    z-index: 2;
    position: fixed;
    left: 0;
    top: 0;
    width: 200px;
    height: 100vh;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 40px;

    .logo {
        width: 160px;
        height: 60px;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 10px;
        overflow: hidden;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);

        img {
            width: 100%;
            height: 100%;
            border-radius: 10px;
        }
    }

    .user-head {
        height: 70px;
        width: 70px;
        margin-top: 70px;
        margin-bottom: 70px;
        background-color: #EAEAEA;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 18px;
        line-height: 70px;
        text-align: center;
        border-radius: 50%;
        cursor: pointer;
    }

    .nav-icon {
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        cursor: pointer;

        // 初始化选项
        .icon-item {
            position: relative;
            margin-bottom: 60px;
            height: 40px;

            .icon {
                opacity: 1;
                width: 100%;
                height: 100%;
                fill: #EAEAEA;
            }

            li {
                display: none;
                position: absolute;
                width: 100%;
                height: 40px;
                font-size: 18px;
                line-height: 40px;
                font-weight: 700;
                top: 0;
                text-align: center;

                &::after {
                    content: '';
                    position: absolute;
                    border-radius: 3px;
                    height: 6px;
                    width: 6px;
                    background-color: #000000;
                    bottom: -2px;
                    left: 50%;
                    transform: translateX(-50%);
                }
            }

            // 当移动到icon-item上时
            &:hover {
                li {
                    display: block;
                    animation: hoverLi 0.2s linear;

                    &::after {
                        animation: hoverLiafter 0.2s linear;
                    }
                }

                .icon {
                    opacity: 0;
                }
            }

        }

        // 选项激活状态下
        .active {
            position: relative;
            margin-bottom: 60px;
            height: 40px;
            border-right: #000000 3px solid;

            .icon {
                opacity: 0;
                width: 100%;
                height: 100%;
                fill: #EAEAEA;
            }

            li {
                display: block;
                position: absolute;
                width: 100%;
                height: 40px;
                font-size: 18px;
                line-height: 40px;
                font-weight: 700;
                top: 0;
                text-align: center;

                &::after {
                    content: '';
                    position: absolute;
                    border-radius: 3px;
                    height: 6px;
                    width: 6px;
                    background-color: #000000;
                    bottom: -2px;
                    left: 50%;
                    transform: translateX(-50%);
                }
            }

        }

    }




}
</style>